<?php
/* Author: tbloc@cantho.gov.vn */
class LoaiHoaHong{  
//Properties
private $LHH_ID;
private $LHH_TEN_LOAI;
private $LHH_TIEN_MAT;
private $LHH_PHAN_TRAM;
private $IS_ACTIVE;
//properties set get 
public function setLHH_ID($LHH_ID) 
{
	$this->LHH_ID = $LHH_ID;
}
public function getLHH_ID()
{
	return $this->LHH_ID;
}	        
public function setLHH_TEN_LOAI($LHH_TEN_LOAI) 
{
	$this->LHH_TEN_LOAI = $LHH_TEN_LOAI;
}
public function getLHH_TEN_LOAI()
{
	return $this->LHH_TEN_LOAI;
}	        
public function setLHH_TIEN_MAT($LHH_TIEN_MAT) 
{
	$this->LHH_TIEN_MAT = $LHH_TIEN_MAT;
}
public function getLHH_TIEN_MAT()
{
	return $this->LHH_TIEN_MAT;
}	        
public function setLHH_PHAN_TRAM($LHH_PHAN_TRAM) 
{
	$this->LHH_PHAN_TRAM = $LHH_PHAN_TRAM;
}
public function getLHH_PHAN_TRAM()
{
	return $this->LHH_PHAN_TRAM;
}	        
public function setIS_ACTIVE($IS_ACTIVE) 
{
	$this->IS_ACTIVE = $IS_ACTIVE;
}
public function getIS_ACTIVE()
{
	return $this->IS_ACTIVE;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `loai_hoa_hong`(                        
			`LHH_ID`, 
				`LHH_TEN_LOAI`, 
				`LHH_TIEN_MAT`, 
				`LHH_PHAN_TRAM`, 
				`IS_ACTIVE` 
		)
	VALUES(
    		:LHH_ID, 
	    		:LHH_TEN_LOAI, 
	    		:LHH_TIEN_MAT, 
	    		:LHH_PHAN_TRAM, 
	    		:IS_ACTIVE 
	    );";
	$parameters = array(
			":LHH_ID", 
				":LHH_TEN_LOAI", 
				":LHH_TIEN_MAT", 
				":LHH_PHAN_TRAM", 
				":IS_ACTIVE" 
		);
    $values = array(  
    		$this->getLHH_ID(), 
	    		$this->getLHH_TEN_LOAI(), 
	    		$this->getLHH_TIEN_MAT(), 
	    		$this->getLHH_PHAN_TRAM(), 
	    		$this->getIS_ACTIVE() 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setLHH_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "update `loai_hoa_hong`
	                set `is_active`=0
	                where `LHH_ID` = :LHH_ID;";
	        $parameters = array(":LHH_ID");
	        $values = array($this->getLHH_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `loai_hoa_hong` SET 
			`LHH_ID`=:LHH_ID,
				`LHH_TEN_LOAI`=:LHH_TEN_LOAI,
				`LHH_TIEN_MAT`=:LHH_TIEN_MAT,
				`LHH_PHAN_TRAM`=:LHH_PHAN_TRAM,
				`IS_ACTIVE`=:IS_ACTIVE
			WHERE `LHH_ID` = :LHH_ID;";
	            $parameters = array(
			":LHH_ID",
				":LHH_TEN_LOAI",
				":LHH_TIEN_MAT",
				":LHH_PHAN_TRAM",
				":IS_ACTIVE"
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getLHH_ID(),
				$this->getLHH_TEN_LOAI(),
				$this->getLHH_TIEN_MAT(),
				$this->getLHH_PHAN_TRAM(),
				$this->getIS_ACTIVE()
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`LHH_ID`,
				`LHH_TEN_LOAI`,
				`LHH_TIEN_MAT`,
				`LHH_PHAN_TRAM`,
				`IS_ACTIVE`
			FROM `loai_hoa_hong` WHERE `LHH_ID` = :LHH_ID and `is_active`=1;";
	$parameters = array(":LHH_ID");
	$values = array($this->getLHH_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setLHH_ID($row->LHH_ID);
		$this->setLHH_TEN_LOAI($row->LHH_TEN_LOAI);
		$this->setLHH_TIEN_MAT($row->LHH_TIEN_MAT);
		$this->setLHH_PHAN_TRAM($row->LHH_PHAN_TRAM);
		$this->setIS_ACTIVE($row->IS_ACTIVE);
	}
	return $this;
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`LHH_ID`,
				`LHH_TEN_LOAI`,
				`LHH_TIEN_MAT`,
				`LHH_PHAN_TRAM`,
				`IS_ACTIVE`
			FROM `loai_hoa_hong` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new LoaiHoaHong();
    	 $obj->setLHH_ID($row->LHH_ID);
		 $obj->setLHH_TEN_LOAI($row->LHH_TEN_LOAI);
		 $obj->setLHH_TIEN_MAT($row->LHH_TIEN_MAT);
		 $obj->setLHH_PHAN_TRAM($row->LHH_PHAN_TRAM);
		 $obj->setIS_ACTIVE($row->IS_ACTIVE);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

